 1.安装jdk1.8
   
   # 下载jdk1.8
   wget --no-cookies --no-check-certificate --header
"Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F;
 oraclelicense=accept-securebackup-cookie"
"http://download.oracle.com/otn-pub/java/jdk/8u141-b15/
336fa29ff2bb4ef291e347e091f7f4a7/jdk-8u261-linux-x64.tar.gz"
  # 解压jdk
  tar -xzf jdk-8u141-linux-x64.tar.gz
  # 配置环境变量
  vim /etc/profile
  export JAVA_HOME=/root/kafka/jdk1.8.0_141
  export PATH=$PATH:$JAVA_HOME/bin
  # 生效
  source /etc/profile
  # 验证 
   java -version
 
 2.安装 Kafka、zk
   
   1).zookeeper
   # 下载kafka安装包
   wget http://archive.apache.org/dist/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
   # 解压kafka
   tar -zxf zookeeper-3.4.14.tar.gz -C /opt
   cd /opt/zookeeper-3.4.14/conf
   # 复制zoo_sample.cfg命名为zoo.cfg 
   cp zoo_sample.cfg zoo.cfg 
   vim zoo.cfg
   # 设置
   dataDir=/var/lagou/zookeeper/data
   编辑/etc/profile
   vim /etc/profile
   # 添加
   export ZOOKEEPER_PREFIX=/opt/zookeeper-3.4.14
   export PATH=$PATH:$ZOOKEEPER_PREFIX/bin
   export ZOO_LOG_DIR=/var/lagou/zookeeper/log
   # 退出vim，让配置生效
   source /etc/profile
   # 验证
   [root@linux21 bin]# cd /opt/zookeeper-3.4.14/bin
   [root@linux21 bin]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.14/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
   
   2).Kafka
   # kafka 下载
   wget http://archive.apache.org/dist/kafka/1.0.2/kafka_2.12-1.0.2.tgz
   tar -zxf kafka_2.12-1.0.2.tgz -C /opt
   # 配置环境变量
   vim /etc/profile
   # 添加以下内容：
   export KAFKA_HOME=/opt/kafka_2.12-1.0.2
   export PATH=$PATH:$KAFKA_HOME/bin
   # 让配置生效
   source /etc/profile
   # 配置kafka 连接Zookeeper地址
   vim /opt/kafka_2.12-1.0.2/config/server.properties
   log.dirs=/var/lagou/kafka/kafka-logs
   zookeeper.connect=linux121:2181/myKafka
   # 启动Zookeeper
   [root@linux121 ~]# zkServer.sh start
   [root@linux121 ~]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: standalone
   # 启动Kafka
   [root@linux121 ~]# kafka-server-start.sh /opt/kafka_2.12-1.0.2/config/
server.properties
   # 此时Kafka是前台模式启动，要停止，使用Ctrl+C; 使用后台启动参数-daemon
   bin/kafka-server-start.sh -daemon config/server.properties
   # 查看Kafka的后台进程：
   ps aux | grep kafka
   # 停止Kafka
   cd /opt/kafka_2.12-1.0.2
   bin/kafka-server-stop.sh
   启动异常处理
   Caused by: java.net.UnknownHostException: mysql-slave1: 未知的名称或服务
    解决方法
    vim  /etc/hosts
    192.168.70.100   linux121
    启动kafka报内存不足的错误
	修改kafka-server-start.sh启动参数
	export KAFKA_HEAP_OPTS="-Xmx256M -Xms128M"
 
 3.kafka常用命令
   
   1).# 列出所有主题
   kafka-topics.sh --list --zookeeper linux121:2181/myKafka
   # 创建主题
   kafka-topics.sh --zookeeper linux121:2181/myKafka --create --topic topic_1
--partitions 3 --replication-factor 3
   # 查询指定主题信息
   kafka-topics.sh --zookeeper linux121:2181/myKafka --describe --topic topic_1
   # 删除指定主题【真正删除还需要在/var/目录下删除kafka-logs文件夹，然后重启kafka】
   kafka-topics.sh --zookeeper linux121:2181/myKafka --delete --topic topic_1
   2).kafka-console-producer.sh用于生产消息
   # 开启生产者
   kafka-console-producer.sh --broker-list linux121:9020 --topic topic_1   
   3).kafka-console-consumer.sh 用于消费消息
   # 开启消费者
   kafka-console-consumer.sh --bootstrap-server linux121:9092 --topic topic_1
   # 开启消费者方式二: 从头消费，不按照偏移量消费
   kafka-console-consumer.sh --bootstrap-server linux121:9092 --topic topic_1 
--from-beginning
 3.配置 nginx的ngx_kafka_module
   
   1).安装nginx
   wget http://nginx.org/download/nginx-1.8.0.tar.gz
   tar -zxvf nginx-1.8.0.tar.gz -C /usr/local/src/
   # 安装git
   yum install -y git
   # 切换到/usr/local/src目录，然后将kafka的c客户端源码clone到本地
   cd /usr/local/src
   git clone https://github.com/edenhill/librdkafka
   # 进入到librdkafka，然后进行编译
   cd librdkafka
   yum install -y gcc gcc-c++ pcre-devel zlib-devel
   ./configure 
   make && make install
   # 安装nginx整合kafka的插件，进入到/usr/local/src，clone nginx整合kafka的源码
   cd /usr/local/src
   git clone https://github.com/brg-liuwei/ngx_kafka_module
   # 进入到nginx的源码包目录下（编译nginx，然后将将插件同时编译）
   cd /usr/local/src/nginx-1.8.0
   ./configure --add-module=/usr/local/src/ngx_kafka_module/
   make & make install
   
   2).修改nginx的配置文件
http {
    kafka;
    kafka_broker_list linux121:9092;
    
    server {
		# topic 消息转发到kafka
		location / {
          	kafka_topic track   
		}
        location = /kafka/track{
             # 开启跨域
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Credentials' 'true';
            kafka_topic track;
        }
    }
}
   3).启动nginx
   /usr/local/nginx/sbin/nginx
   # 查看nginx进程
   ps -ef | grep nginx
   netstat -anpt | grep nginx
   4).异常处理
   error while loading shared libraries: librdkafka.so.1: 
cannot open shared object file: No such file or directory
   # 解决办法：加载so库
   echo "/usr/local/lib" >> /etc/ld.so.conf
   ldconfig
   5).测试消息发送
   # 启动成功后，向kafka集群发送消息测试
   curl linux121:80/kafka/track -d "message send to kafka topic track"
   kafka-console-consumer.sh --bootstrap-server linux121:9092 
--topic track --from-beginning

   
 4.页面开发
   